<template>
  <div class="bottom-bar">
    <div class="check-content">
      <CheckGoodsBtn class="checked-button" :isSelected="isSelectedAll" @click.native="changSelected"/>
      <span>全选</span>
    </div>
    <div class="price">
      合计{{ totalPrice }}
    </div>
    <div class="calculate">
      去结算: {{ checkLength }}
    </div>
  </div>
</template>

<script>
import CheckGoodsBtn from 'components/content/checkGoodsBtn/CheckGoodsBtn'
import { mapGetters } from 'vuex'
export default {
  name: 'CartBottomBar',
  components: {
    CheckGoodsBtn
  },
  computed: {
    ...mapGetters(['cartList']),
    totalPrice() {
      return '￥'+this.cartList
        .filter(item => item.isSelected)
          .reduce((pre,item) => {return pre+item.price * item.count},0);
    },
    checkLength() {
      return this.cartList.filter(item => item.isSelected).length;
    },
    isSelectedAll() {
      return this.cartList.length == 0 ? false : this.cartList.every(item => item.isSelected == true)
    }
  },
  methods: {
    changSelected() {
      // if(this.isSelectedAll) {
      //   this.cartList.forEach(item => item.isSelected =false);
      // }
      this.isSelectedAll ? this.cartList.forEach(item => item.isSelected = false) : this.cartList.forEach(item => item.isSelected = true);
    }
  }
}
</script>

<style scoped>
  .bottom-bar {
    position: relative;
    display: flex;
    height: 40px;
    background: #eee;
    line-height: 40px;
  }
  .check-content {
    display: flex;
    align-items: center;
    margin-right: auto;
  }
  .check-content span {
    height: 100%;
    box-sizing: border-box;
    font-size: 16px;
  }
  .checked-button {
    width: 20px;
    height: 20px;
    line-height: 20px;
    margin: 0 3px;
  }
  .price {
    margin-left: 20px;
    font-size: 16px;
  }
  .calculate {
    text-align: center;
    line-height: 40px;
    height: 100%;
    width: 25%;
    color: red;
    border-radius: 3px;
    margin:0 10px;
    font-weight: bold;
    font-size: 16px;
    background: rgba(255, 255, 0,.6);
  }
</style>